package yk.dao;

import com.yk.pojo.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class PayMentMapper {

    @Autowired
    JdbcTemplate jdbcTemplate;

    public Payment queryById(Long id) {
        return jdbcTemplate.queryForObject("select * from payment where id =?",
                new Object[]{id}, new BeanPropertyRowMapper<Payment>(Payment.class));
    }

    public List<Payment> queryAll() {
        return jdbcTemplate.query("select * from payment", new BeanPropertyRowMapper(Payment.class));
    }

    public int insert(Payment payment) {
        int update = jdbcTemplate.update("insert into payment(serial) values (?)", payment.getSerial());
        return update;
    }

}
